package org.tang.data.entity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import org.tang.data.common.Constant;

public class DayK {
	
	private List<DayKEntity> dayKList = new ArrayList<DayKEntity>();
	private String stockNumber;
	
	public DayK(String stockNumber) throws Exception{
		this.stockNumber = stockNumber;
		File file = new File(Constant.dirPre+Constant.dayKDir+this.stockNumber+".txt");
		BufferedReader reader = new BufferedReader(new FileReader(file));
		String line = null;
		while((line=reader.readLine())!=null)
			dayKList.add(DayKEntity.instance(line));
		reader.close();
	}
	
	public int getIndex(String dateString){
		for(int i=dayKList.size()-1;i>=0;i--)
			if(dateString.equals(dayKList.get(i).date))
				return i;
		return -1;
	}
	
	public DayKEntity getDayKEntity(int index){
		if(index < 0 || index >= dayKList.size())
			return null;
		return dayKList.get(index);
	}
}
